home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / mAz Lite 1.0 / lflare.wdl < prev    next >
Encoding:
Text File  |  2003-03-17  |  5.8 KB  |  251 lines

  1. // Template file v5.202 (02/20/02)
  2. ////////////////////////////////////////////////////////////////////////
  3. // File: lflare.wdl
  4. //        WDL code for lens flare and lighting effects
  5. ////////////////////////////////////////////////////////////////////////
  6. //
  7. ////////////////////////////////////////////////////////////////////////
  8.  
  9. var flare_trace_mode; // used to trace to the sun
  10.  
  11. var qLensFlare = -1;    // -1 == not created
  12.                              // 0 == off
  13.                              // 1 == on
  14.                               // otherwise == turning off
  15.  
  16.  
  17. string    str_skytex = "sky";    // if the first part of the texture scanned matches this, it is sky
  18.  
  19. // use the skill1 parameter to store a number in a sprite entity
  20. // The pivot distance is the percent distance between the screen center
  21. //(where pivot_dist = 0) and the sun (pivot_dist = 1).
  22. define pivot_dist,skill1;
  23.  
  24. // this is the sun itself
  25. entity flareSun_ent
  26. {
  27.     type = <flare2.pcx>; // uses a sprite
  28.     view = CAMERA;         // same camera parameters as the default view
  29.     layer = -6;             // displayed beneath other entity layers
  30.     pivot_dist = 1;        // distance factor from 'pivot point', must be 1 for sun
  31.     scale_x = 2;            // sun is two times as large as the flares
  32.     scale_y = 2;
  33. }
  34.  
  35. // The 8 lens flare entities
  36. entity flare0_ent
  37. {
  38.     type = <flare0.pcx>;
  39.     view = CAMERA;
  40.     layer = -6;
  41.     pivot_dist = 0.75;    // at distance 0 is the pivot point - the screen center
  42. }
  43. entity flare1_ent
  44. {    // 7 lens reflections
  45.     type = <flare1.pcx>;
  46.     view = CAMERA;
  47.     layer = -6;
  48.     pivot_dist = 0.55;
  49. }
  50. entity flare2_ent
  51. {
  52.     type = <flare2.pcx>;
  53.     view = CAMERA;
  54.     layer = -6;
  55.     pivot_dist = 0.35;
  56. }
  57.  
  58. entity flare3_ent
  59. {
  60.     type = <flare3.pcx>;
  61.     layer = -6;
  62.     view = CAMERA;
  63.     pivot_dist = 0.15;
  64.     scale_x = 1.5;
  65.     scale_y = 1.5;
  66. }
  67.  
  68. entity flare4_ent
  69. {
  70.     type = <flare0.pcx>;
  71.     layer = -6;
  72.     view = CAMERA;
  73.     pivot_dist = -0.25;
  74. }
  75.  
  76. entity flare5_ent
  77. {
  78.     type = <flare1.pcx>;
  79.     layer = -6;
  80.     view = CAMERA;
  81.     pivot_dist = -0.45;
  82. }
  83.  
  84. entity flare6_ent
  85. {
  86.     type = <flare2.pcx>;
  87.     layer = -6;
  88.     view = CAMERA;
  89.     pivot_dist = -0.65;
  90. }
  91.  
  92. entity flare7_ent
  93. {
  94.     type = <flare3.pcx>;
  95.     layer = -6;
  96.     view = CAMERA;
  97.     pivot_dist = -0.85;
  98.     scale_x = 1.5;
  99.     scale_y = 1.5;
  100. }
  101.  
  102.  
  103. // Desc: this function takes an entity as parameter.
  104. function flare_init(flare_ent)
  105. {
  106.     my = flare_ent;    // necessary because function parameters have no type
  107.     my.visible = off;    // start with flares off
  108.     if (video_depth > 8)     // D3D mode?
  109.     {
  110.         ent_alphaset(0,10);    // create an alpha channel (won't work with standard edition)
  111.         my.bright = on;
  112.         my.flare = on;
  113.     }
  114.     else
  115.     {
  116.         my.transparent = on;    // looks lousy in 8 bit, though
  117.     }
  118. }
  119.  
  120.  
  121. // Desc: places a flare at temp.x/temp.y deviations from screen center
  122. function flare_place(flare_ent)
  123. {
  124.     my = flare_ent;
  125.     my.visible = on;
  126.  
  127.     // multiply the pixel deviation with the pivot factor,
  128.     // and add the screen center
  129.     my.x = temp.x*my.pivot_dist + 0.5*screen_size.x;
  130.     my.y = temp.y*my.pivot_dist + 0.5*screen_size.y;
  131.     my.z = 750;    // screen distance, determines the size of the flare
  132.     rel_for_screen(my.x,camera);
  133. }
  134.  
  135.  
  136. // Desc: this function turns all the flareN_ent (and flareSun_ent) on or
  137. //     off depending on the value pass in 'on_off'.
  138. //
  139. function flare_visible(on_off)
  140. {
  141.     flareSun_ent.visible = on_off;
  142.  
  143.     flare0_ent.visible = on_off;
  144.     flare1_ent.visible = on_off;
  145.     flare2_ent.visible = on_off;
  146.     flare3_ent.visible = on_off;
  147.     flare4_ent.visible = on_off;
  148.     flare5_ent.visible = on_off;
  149.     flare6_ent.visible = on_off;
  150.     flare7_ent.visible = on_off;
  151. }
  152.  
  153.  
  154.  
  155. // Desc: setup the lens flare effect
  156. function lensflare_create()
  157. {
  158.     // set alpha values for each entity
  159.     flare_init(flare0_ent);
  160.     flare_init(flare1_ent);
  161.     flare_init(flare2_ent);
  162.     flare_init(flare3_ent);
  163.     flare_init(flare4_ent);
  164.     flare_init(flare5_ent);
  165.     flare_init(flare6_ent);
  166.     flare_init(flare7_ent);
  167.  
  168.     flare_init(flareSun_ent);    // <<the sun flare
  169.  
  170. //  set the trace mode to be used to trace to the sun
  171.     flare_trace_mode = IGNORE_PASSABLE + IGNORE_MODELS; //IGNORE_PASSABLE needed for tracing through the sky box)
  172.  
  173.     qLensFlare = 0;    // start 'off'
  174. }
  175.  
  176.  
  177. // Desc: start and animate a lens flare effect as long as qLensFlare == 1
  178. //
  179. function    lensflare_start()
  180. {
  181.  
  182.     if(qLensFlare == -1) // create the lens flares
  183.     {
  184.         lensflare_create();
  185.     }
  186.  
  187.     if(qLensFlare == 1)  // lens flare already started
  188.     {
  189.         return;
  190.     }
  191.  
  192.     // allow for setup time for "lensflare_create"
  193.     //(if it was called right before this function)
  194.     wait(1);
  195.     qLensFlare = 1;    // mark lens flare as on
  196.  
  197.     // place lens flares
  198.     while(qLensFlare == 1)
  199.     {
  200.         wait(1);    // animate each cycle
  201.         // Animate lens flare
  202.         vec_set(temp,sun_pos);
  203.         if(vec_to_screen(temp,camera) == 0)
  204.         {
  205.         // Outside of View cone... remove lens flares
  206.             flare_visible(off);
  207.         }
  208.         else     // check for trace to sun
  209.         {
  210.         // trace to the 'sun'
  211.             trace_mode = flare_trace_mode + scan_texture;   // ++ added scan_texture
  212.         // check if line to sun is blocked
  213.             if (trace(camera.x,sun_pos) != 0)
  214.             {
  215.                 if( str_cmpni(tex_name,str_skytex) == 0) // object blocking us is not sky
  216.                 {
  217.                 // Something is blocking us.. hide lens flare
  218.                     flare_visible(off);
  219.                     continue;    // continue loop
  220.                 }
  221.             }
  222.  
  223.  
  224.             // temp now contains the sun XY screen position
  225.             // subtract the screen center, needed for flare_place()
  226.             temp.x -= 0.5 * screen_size.x;
  227.             temp.y -= 0.5 * screen_size.y;
  228.             flare_place(flareSun_ent);
  229.  
  230.             // place all flares according to deviation and their pivot distance
  231.             flare_place(flare0_ent);
  232.             flare_place(flare1_ent);
  233.             flare_place(flare2_ent);
  234.             flare_place(flare3_ent);
  235.             flare_place(flare4_ent);
  236.             flare_place(flare5_ent);
  237.             flare_place(flare6_ent);
  238.             flare_place(flare7_ent);
  239.         }
  240.     }
  241.  
  242.     // Remove lens flares
  243.     flare_visible(off);
  244.     qLensFlare = 0;     // mark lens flare as off
  245. }
  246.  
  247. // Desc: stop the lens flare effect
  248. function lensflare_stop()
  249. {
  250.     qLensFlare = .5;    // signal to stop
  251. }